package cn.huas.sqls;
import java.io.IOException;


public class Command {

//	public static void main(String[] args) throws IOException {
//		Command com = new Command();
//		com.checkConmmand("localhost","root","admin", "schedule", "D:/test.sql");
//	}
	 
	public boolean execCmd(String cmd) {
		StringBuffer str = new StringBuffer();
		str.append("cmd.exe /c \"").append(cmd).append("\"");
		System.out.println(str);		//打印执行的命令
		try {
				Runtime.getRuntime().exec(str.toString());
				return true;
		} catch (IOException e) {
			e.printStackTrace();
		} 

		return false;
	}
	
	public boolean checkConmmand(String ip, String username, String password,String datebaseName, String filePath) {
		String strCommand = "mysqldump -h "+ip+" -u" + username + " -p" + password + " " + datebaseName + " > " + filePath;
		boolean result = execCmd(strCommand);
		System.out.println(result);
		if(result)return true;
		else 
			return false;
	}
}